﻿using GatewayServerService.Data;
using System.Data;
using UtilsBase;
using UtilsCache;
using UtilsORM;
using UtilsORM.MySqlData;

////using System.Web.Script.Serialization;

namespace GatewayServerService.Data
{
    public class DBIotDeviceModelCache
    {




        /// <summary>
        /// 增加型号缓存 
        /// </summary>
        /// <returns></returns>
        public iot_device_model getModelByCache(string mguid)
        {


            iot_device_model model = UtilMemoryCacheHelper.StringGet<iot_device_model>("deviceModelOne_" + mguid);//数据太多，报错
            if (model == null)
            {
                EFYihongIotContext ef = new EFYihongIotContext();
                model = ef.iot_device_model.Where(c => c.m_guid == mguid && c.m_status == 0).FirstOrDefault();
                UtilMemoryCacheHelper.StringSet("deviceModelOne_" + mguid, model, 1);
            }
            return model;// ef.iot_device_model.Where(c => c.m_guid == mguid && c.m_status == 0).FirstOrDefault(); ;
        }

        /// <summary>
        /// 增加型号缓存 
        /// </summary>
        /// <returns></returns>
        public iot_device_model getModelByDeviceCache(string dguid)
        {
            iot_device_model model = UtilMemoryCacheHelper.StringGet<iot_device_model>("getModelByDeviceCache_" + dguid);//数据太多，报错
            if (model == null)
            {
                EFYihongIotContext ef = new EFYihongIotContext();
                iot_device iot_Device = new DBIotDeviceCache().getClientDeviceByCache(dguid);
                if (iot_Device == null)
                {
                    return null;
                }
                model = ef.iot_device_model.Where(c => c.m_guid == iot_Device.d_model_guid && c.m_status == 0).FirstOrDefault();
                UtilMemoryCacheHelper.StringSet("getModelByDeviceCache_" + dguid, model, 30);
            }
            return model;
        }

    }
}
